<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel='stylesheet' href="css/search_result.css">
        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <link href="https://cdn.bootcdn.net/ajax/libs/animate.css/3.7.2/animate.min.css" rel="stylesheet">
        <title>查询结果</title>
    </head>

    <body style="background: url(../webImgs/bg11.jpg);background-size: cover;">
        <?php
        include_once 'mydb.php';
        require_once 'pinyin.class';

        $pdo = getConnect();

        $pinyin = new EJCMS_Pinyin();

//        $plName = $_GET['plname'];
//        $plantName = $_POST['name'];
//
//        $queryPlant = "select Search_name, Introduction from plants where Search_name like '%" . $plantName . "%'";
//        $prepared_Statement = $pdo->prepare($queryPlant);
//        $result = $prepared_Statement->execute();
        ?>
        <div class="head_link">
            <a href="plantsDictionary.html" class="link">植物字典</a>
            <a href="home.php" class="link">首页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|</a>
        </div>

        <div id="head"></div>
        <form action="search_result.php" method="POST">
            <div id="searchbar">
                <input type="search" class="input_bar" placeholder="请输入您要搜索的植物" value="" name="plant_name">
                <!--                <button class="search_button" onclick="Search_plant()">Search</button>-->
                <input type="submit" class="search_button" value="Search">
            </div>
        </form>

        <div class="show_result">
            <!--<form action="plant_introduction.php" method="GET">-->
            <form action="plant_introduction.php" method="GET">
                <?php
//                $plname = 1;
//                $plName = 2;
//
//                $plname = $_GET['plantname_intro'];
//                $plName = $_POST['plant_name'];
//                
//                if ($plname!=1) {
//                    $plantName = $plname;
//                } else {
//                    $plantName = $plName;
//                }

                $plantName = $_POST['plant_name'];

//                $seachforpl = $plantName;

                $queryForIntro = 'select ID, Search_name, Introduction from plants where Search_name like "%' . $plantName . '%"';

//            $prepared_Statement = $pdo->prepare($queryForIntro);
////            $resultSetB = $pdo->query($queryForIntro);
//            $result = $prepared_Statement->execute();

                $resultSet = $pdo->query($queryForIntro);

                $num = 1;

                if ($resultSet) {
                    $rows = $resultSet->fetchAll();

                    foreach ($rows as $Row) {
//                   foreach ($resultSet as $Row) {
                        $pln = $Row['Search_name'];

                        $plnpy = $pinyin->encode($pln, "all");
//                        echo $plnpy;

                        echo "<div class='single_result' >";

//                echo '<img class="plant_img" onclick="showIntro()" src="../plantsImg/' + $plantName + '1.jpg">';
                        echo "<a href=plant_introduction.php?&plantID=" . $Row['ID'] . "><img class='plant_img' src='../plantsImg/" . $plnpy . "1.jpg'></a>";
                        echo '<input type="button" class="upon" onclick="movetofirst(this)" value="结果置顶">';

                        echo "<div class='brief'><a href=plant_introduction.php?plantID=" . $Row['ID'] . " style='text-decoration: none;color:black'>";
                        echo '<h3>';
                        echo $Row['Search_name'];
                        echo '</h3>';

                        echo '<p>';
                        echo $Row['Introduction'];
                        echo '</p>';

                        echo '</a></div>';

                        echo '</div>';

                        $num++;
                    }
                }
//            else {
//                echo "execute query failed. <br>";
//                echo 'the error info is ' . print_r($pre_stmt->errorInfo(), TRUE) . '<br>';
//            }
                ?>

                <!--            <div class="single_result">
                                <img class="plant_img" src="./webImgs/dahuamachixian3.jpg" onclick="showIntro()">
                                 <button class="upon" onclick="movetofirst(this)">结果置顶</button> 
                                <input type="button" class="upon" onclick="movetofirst(this)" value="结果置顶">
                                <div class="brief" onclick="showIntro()">
                                    <h3>大花马齿苋</h3>
                                    <p>拉丁名: Portulaca grandiflora Hook.
                                        一年生草本，高10-30厘米。茎平卧或斜升，紫红色，多分枝，节上丛生毛。叶密集枝端，较下的叶分开，不规则互生，叶片细圆柱形，无毛。花单生或数朵簇生枝端，直径2.5-4厘米，日开夜闭；总苞8-9片，叶状，轮生，具白色长柔毛；花瓣5或重瓣，倒卵形，顶端微凹，长12-30毫米，红色、紫色或黄白色。蒴果近椭圆形，盖裂；种子细小，多数，圆肾形，直径不及1毫米。花期6-9月，果期8-11月。
                                    </p>
                                </div>
                            </div>-->
            </form>
        </div>
    </body>

    <script>
        $(document).ready(function () {
            $('h3').hide().fadeIn(800);
            $('p').hide().fadeIn(1000);
            $('img').hide().fadeIn('slow');
        });

//                var id = location.search.substring(1);
//                // if (id) document.getElementById('img' + id).style.display = ''
//                if (id)
//                    document.getElementById('img').src = "./webImgs/dahuamachixian" + id + ".jpg";
////         alert("已成功设置该图片为搜索结果图");

        //搜索按钮
//        var input_value = document.getElementByClassName("input_bar").value;
//        var input_name = input_value;

        function Search_plant() {
//            var input_value = document.getElementByClassName("input_bar").value;

            //        // 创建XMLHttpRequest对象(HTTP请求对象)
            //        if (window.XMLHttpRequest)
            //        {
            //            // code for IE7+, Firefox, Chrome, Opera, Safari
            //            xmlhttp = new XMLHttpRequest();
            //        } else {
            //            // code for IE6, IE5
            //            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            //        }
            //        // 定义事件处理程序
            //        xmlhttp.onreadystatechange = function ()
            //        {
            //            // 判断XMLHttpRequest对象的状态和HTTP状态代码
            //            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            //            {
            //                document.getElementByClassName("input_bar").innerHTML = xmlhttp.responseText;
            //            }
            //        }
            //        // 初始化待发送给Web服务器的请求
            //        xmlhttp.open("GET", "SearchForResult.php?name=" + input_name, true);
            //        // 向服务器发送当前请求
            //        xmlhttp.send();
            //
            ////                alter("name=" + $input_name);
            //
            //        window.location.href = 'search_result';
        }


        function movetofirst(now) {
            $(".show_result").children(":first").before(now.parentNode);
        }


//        function showIntro(plantid) {
//            // 创建XMLHttpRequest对象(HTTP请求对象)
//            if (window.XMLHttpRequest)
//            {
//                // code for IE7+, Firefox, Chrome, Opera, Safari
//                xmlhttp = new XMLHttpRequest();
//            } else {
//                // code for IE6, IE5
//                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//            }
//            // 定义事件处理程序
//            xmlhttp.onreadystatechange = function ()
//            {
//                // 判断XMLHttpRequest对象的状态和HTTP状态代码
//                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
//                {
////                    document.getElementByClassName("input_bar").innerHTML = xmlhttp.responseText;
//                }
//            }
//            // 初始化待发送给Web服务器的请求
//            xmlhttp.open("GET", "plant_introduction.php?id=" + plantid, true);
//            // 向服务器发送当前请求
//            xmlhttp.send();
//            window.location.href = "plant_introduction.php";
//        }

    </script>

</html>